local Systems={}
local System={isSystem=true,Tuple={},priority=0}
function System:new(o)--System基类的构造函数
    o=o or {}
    self.__index=self
    setmetatable(o, self)
    return o
end

function System:addtoTuple(Component)--将一个component放到对应System的tuple中
   assert(Component.isComponent~=nil, "is not a component")
  table.insert(self.Tuple,Component)
end

function System:setPriortiy(world,pri)--设置system的优先级
    assert(type(pri)~=type(10),"invalid type for priority")
    for sys in world.systems do
        -- statements
        assert(pri~=sys.priority, "has same priority")
    end
    self.priority=pri
end

function System:hasComponent(Component)--检查system中是否有该component
    assert(self.Tuple~=nil,"has no Tuple yet")
    if (self.Tuple.Component==nil) then
        return false
    end
    return true
end

function System:update(world)
    for Entity in world.Entities do--遍历所有Entity
        --statements
        local dealthisEntity=true
        for component in Entity.Components do--遍历Entity里所有的Component
            -- statements
            dealthisEntity=self:hasComponent(component)
        end
        if(dealthisEntity==true) then
         print("do something here!")
        -------------------
        ----处理逻辑-------
        -------------------
        end
    end
end
-------------------------------------------------------------------------------------
--下方写system--
--[[例如
System:new(MoveSystem)
MoveSystem:addtoTuple(Position)
MoveSystem:addtoTuple(Speed)
MoveSystem:addtoTuple(CharacterName)
MoveSystem:setPriority(world,10)
]]--
-------------------------------------------------------------------------------------

return Systems